<h1>DefineImage</h1>

<p>DefineImage is used to define an image compressed using the lossless zlib compression algorithm. The class supports colour-mapped images where the image data contains an index into a colour table or images where the image data specifies the colour directly.</p>

<table>

<tr>
<th nowrap>Field Name</th>
<th>Type</th>
<th>Size</th>
<th>Description</th>
</tr>

<tr>
<td nowrap valign="top">type</td>
<td nowrap valign="top">unsigned bit</td>
<td nowrap valign="top" align="right">10</td>
<td>Identifies the DefineImage instruction when it is encoded. It is encoded 
with the length field as a 16-bit integer (Little-endian byte order).</td>
</tr>

<tr>
<td nowrap valign="top">length</td>
<td nowrap valign="top">unsigned bit</td>
<td nowrap valign="top" align="right">6</td>
<td>The length in bytes of the body of the instruction when it is encoded. If the length is greater 
than 62 then this field is set to 0x3F and the length is encoded using the 
extendedLength field. Encoded with the type field as a 16-bit integer.</td>
</tr>

<tr>
<td nowrap valign="top">extendedLength</td>
<td nowrap valign="top">unsigned int</td>
<td nowrap valign="top" align="right">32</td>
<td>Optional. Contains the length in bytes of the encoded instruction if it is
greater than 62 bytes. If the length is 62 bytes or less then this field is 
omitted.</td>
</tr>

<tr>
<td nowrap valign="top">identifier</td>
<td nowrap valign="top">unsigned int</td>
<td nowrap valign="top" align="right">16</td>
<td>The unique identifier for this image definition. This is used when adding or removing 
the shape from the display list or when the shape is used as part of another 
object such as a button.</td>
</tr>

<tr>
<td nowrap valign="top">format</td>
<td nowrap valign="top">unsigned int</td>
<td nowrap valign="top" align="right">8</td>
<td>The type of image encoded: 3 == 8-bit colour-mapped image, 4 == 15-bits per
pixel RGB image and 5 == 24-bits per pixel RGB image.</td>
</tr>

<tr>
<td nowrap valign="top">width</td>
<td nowrap valign="top">unsigned int</td>
<td nowrap valign="top" align="right">16</td>
<td>Width of the image in pixels, NOT twips. 1 pixel = 20 twips.</td>
</tr>

<tr>
<td nowrap valign="top">height</td>
<td nowrap valign="top">unsigned int</td>
<td nowrap valign="top" align="right">16</td>
<td>Height of the image in pixels, NOT twips.  1 pixel = 20 twips.</td>
</tr>

<tr>
<td nowrap valign="top">tableSize</td>
<td nowrap valign="top">unsigned int</td>
<td nowrap valign="top" align="right">8</td>
<td>Optional. The number of entries in the colour table - which is compressed as part of 
the image. Each entry in the colour table contains one byte each for the red, 
green and blue colour channels. The colour table is only used for indexed colour 
images. The table is not used when the colour is specified directly in each 
pixel. Only applies to images where format = 3.</td>
</tr>

<tr>
<td nowrap valign="top">compressedData</td>
<td nowrap valign="top">byte[n]</td>
<td nowrap valign="top" align="right">&nbsp;</td>
<td>An array of bytes containing the zlib compressed colour table and image.</td>
</tr>

</table>

<p>For colour-mapped images the colour table contains up to 256, 24-bit colours. 
The image contains one byte for each pixel which is an index into the table to 
specify the colour for that pixel. The colour table and the image data are 
compressed as a single block, with the colour table placed before the image.</p>

<p>For images where the colour is specified directly, the image data contains 
either 16 or 24 bit colour values. For 16-bit colour values the most significant 
bit is zero followed by three, 5-bit fields for the red, green and blue channels:</p>

<pre>
            +-+--------+--------+--------+
            |0|   Red  |  Green |  Blue  |
            +-+--------+--------+--------+
           15                            0
</pre>

<p>Four bytes are used to represent 24-bit colours. The first byte is always set 
to zero and the following bytes contain the colour values for the red, green and 
blue colour channels.</p>

<p>The number of bytes in each row of an image must be aligned to a 32-bit word 
boundary. For example if an image if an icon is 25 pixels wide, then for an 8-bit 
colour mapped image an additional three bytes (0x00) must be used to pad each row; 
for a 16-bit direct mapped colour image an additional two bytes must be used as 
padding.</p>

<p>The image data is stored in zlib compressed form within the object. For 
colour-mapped images the compressed data contains the colour table followed by 
the image data. The colour table is omitted for direct-mapped images.</p>

<h2>History</h2>

<p>The DefineImage class represents the DefineBitsLossless tag from the Macromedia 
Flash (SWF) File Format Specification. It was introduced in Flash 2.</p>
